package xyz.longicorn.driver.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import xyz.longicorn.driver.config.BizException;

import java.io.Serializable;
import java.util.Date;

@Data
@Accessors(chain = true)
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class ApiResult implements Serializable {
    private int code;
    private String message;
    private Object data;

    public static ApiResult success(Object data) {
        return new ApiResult(0, "success", data);
    }

    public static ApiResult error(int code, String message) {
        return new ApiResult(code, message, null);
    }

    public static ApiResult error(BizException e) {
        return new ApiResult(e.getCode(), e.getMessage(), null);
    }
}
